package com.nd.controller.admin;



import com.nd.pojo.bean.Ad;
import com.nd.pojo.bo.AdAddBo;
import com.nd.pojo.bo.AdDeleteBo;
import com.nd.pojo.bo.AdQueryBo;
import com.nd.pojo.bo.LoginAdminBo;
import com.nd.pojo.vo.AdAddVo;
import com.nd.pojo.vo.AdQueryDataVo;
import com.nd.pojo.vo.BaseRespVo;
import com.nd.service.AdService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/ad")
public class AdController  {

    @Autowired
    AdService adService;

    @RequestMapping("list")
    public BaseRespVo query(AdQueryBo adQueryBo){

        AdQueryDataVo adQueryDataVo = adService.queryAll(adQueryBo.getPage(), adQueryBo.getLimit(),
                adQueryBo.getSort(),adQueryBo.getOrder(), adQueryBo.getName(), adQueryBo.getContent());


        return BaseRespVo.ok(adQueryDataVo);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody AdDeleteBo adDeleteBo){

        Integer code = adService.delete(adDeleteBo);

        if (code == 1) {
            return BaseRespVo.ok();
        }

        return BaseRespVo.fail();
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody AdAddBo adAddBo){

        Ad adAddVo = adService.create(adAddBo);

        return BaseRespVo.ok(adAddVo);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Ad ad){

        Ad ad1 = adService.update(ad);

        return BaseRespVo.ok(ad1);

    }


}
